package com.example.service.impl;

import com.example.mapper.fixtureTechConditionMapp;
import com.example.pojo.fixtureTechConditionPojo;
import com.example.service.fixtureTechConditionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
import java.util.UUID;

@Service
public class fixtureTechConditionImpl implements fixtureTechConditionService {
    @Autowired
    private fixtureTechConditionMapp fixtureTechConditionMapp;
    //insertOne方法接收一个fixtureTechConditionPojo对象作为参数，执行插入操作后，不返回任何结果（void）
    public void insertOne(fixtureTechConditionPojo pojo){
        //定义创建时间生成规则
        pojo.setCreate_time(LocalDateTime.now());
        //定义修改时间生成规则
        pojo.setUpdate_time(LocalDateTime.now());
        //调用 Mapper 插入数据
        fixtureTechConditionMapp.insertOne(pojo);
    };

    // 根据部门分页查询工装技术条件数据
    public List<fixtureTechConditionPojo> queryByDepartment(String department){
        // 调用Mapper方法，传入部门参数
        List<fixtureTechConditionPojo> pojoList = fixtureTechConditionMapp.queryByDepartment(department);
        return pojoList;
    };

    //根据ID，选择一行数据
    public fixtureTechConditionPojo selectById(String id){
        fixtureTechConditionPojo pojo=fixtureTechConditionMapp.selectById(id);
        return pojo;
    }

    //根据IdUse编辑某一行数据
    public void editOneById(fixtureTechConditionPojo pojo){
        //定义修改时间生成规则
        pojo.setUpdate_time(LocalDateTime.now());
        //调用 Mapper 编辑数据
        fixtureTechConditionMapp.editOneByIdUse(pojo);
    }

    //查询某一字段为某值的数据
    public List<fixtureTechConditionPojo> queryOneField(Map<String, Object> map){
        System.out.println(map);
        String fieldName = map.get("fieldName").toString();
        String fieldValue = map.get("fieldVal").toString();
        List<fixtureTechConditionPojo> fixtureTechConditionPojos=fixtureTechConditionMapp.queryOneField(fieldName, fieldValue);
        return fixtureTechConditionPojos;
    }

    //查询某两个字段为某值的数据
    public List<fixtureTechConditionPojo> queryTwoFields(Map<String, Object> map){
        String fieldName1 = String.valueOf(map.get("fieldName1"));
        String fieldValue1 = String.valueOf(map.get("fieldValue1"));
        String fieldName2 = String.valueOf(map.get("fieldName2"));
        String fieldValue2 = String.valueOf(map.get("fieldValue2"));
        List<fixtureTechConditionPojo> fixtureTechConditionPojos=fixtureTechConditionMapp.queryTwoFields(fieldName1,fieldValue1,fieldName2,fieldValue2);
        return fixtureTechConditionPojos;

    }

    //删除工装技术条件表中fieldName中为fieldVal的数据
    public void deleteOneField(String fieldName, String fieldVal){
        fixtureTechConditionMapp.deleteOneField(fieldName,fieldVal);
    }

    //分页查询工装技术条件
    public List<fixtureTechConditionPojo> queryByPage(Map<String, Object> map){
        Integer page =(Integer) map.get("page");
        Integer size=(Integer) map.get("size");
        String department=(String) map.get("department");
        Integer startRow=page*size;
        List<fixtureTechConditionPojo> fixtureTechConditionPojos=fixtureTechConditionMapp.queryByPage(startRow, size, department);
        return fixtureTechConditionPojos;
    }

    //查询所有工装技术条件条数
    public Integer queryQuantity(Map<String,Object> map){
        String department=(String) map.get("department");
        Integer quantity= fixtureTechConditionMapp.queryQuantity(department);
        return quantity;
    }

    //查询所有工装技术条件中不重复的图号
    public List<fixtureTechConditionPojo> queryDrawingNumber(){
        List<fixtureTechConditionPojo> pojos=fixtureTechConditionMapp.queryDrawingNumber();
        return pojos;
    }
}
